package com.fyzk.view;

import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.bean.LotteryLayoutItem;
import com.tyjc.lottery.R;
import com.fyzk.view.ViewCallBack.CountDownInterface;

public class LotteryItemView extends LinearLayout implements CountDownInterface{

	private Context context;

	private ImageView img;
	private ImageView lott_tag;
	private TextView name;
	private TextView jieZhi;
	private TextView description;
	private TextView issue;

	private int lotteryId;
	private int logoId;
	private boolean isLeft;


	private LotteryLayoutItem lotteryInfo;

	public LotteryItemView(Context context) {
		super(context);
		this.context = context;
		init();

	}

	public LotteryItemView(Context context,  AttributeSet attrs) {
		super(context,attrs);
		this.context = context;
		init();

	}

	public LotteryItemView(Context context,AttributeSet attrs, int defStyleAttr) {
		super(context,attrs,defStyleAttr);
		this.context = context;
		init();

	}

	public LotteryItemView(Context context,int logoId) {
		this(context);
		this.logoId = logoId;
	}
	
	@Override
	public boolean equals(Object o) {
		if(o == null){
			return false;
		}
		if(o instanceof LotteryItemView){
			LotteryItemView item = (LotteryItemView) o;
			if(item.logoId == this.logoId){
				return true;
			}else{
				return false;
			}
		}
		return super.equals(o);
	}
	
	@Override
	public int hashCode() {
		return this.logoId;
	}

	private void init() {
		View.inflate(context, R.layout.main_vp_main_new, this);
		img = (ImageView) findViewById(R.id.vp_main_title);
		lott_tag = (ImageView) findViewById(R.id.lott_tag);
		name = (TextView) findViewById(R.id.vp_main_name);
		jieZhi = (TextView) findViewById(R.id.vp_main_tv_jiezhi);
		description = (TextView) findViewById(R.id.vp_main_description);
		issue = (TextView) findViewById(R.id.vp_main_issue);
//		ViewCallBack.getInstance().AttachCountDownObj(this);
	}


	public void setLotteryInfo(LotteryLayoutItem lotteryInfo) {
		this.lotteryInfo = lotteryInfo;
			if(lotteryInfo.getInSale() == 1){//在售
				if(lotteryInfo.getAddPrize() == 1){//加奖
					lott_tag.setImageDrawable(getResources().getDrawable(R.drawable.lott_promotion));
				}else{
					if(lotteryInfo.getTodayOpen() == 1){//今日开奖
						lott_tag.setImageDrawable(getResources().getDrawable(R.drawable.lott_todayo));
					}else{
						lott_tag.setVisibility(View.INVISIBLE);
					}
				}
			}else{
				lott_tag.setImageDrawable(getResources().getDrawable(R.drawable.lott_unsale));
			}

		description.setText(Html.fromHtml(lotteryInfo.getDescription()));
		name.setText(lotteryInfo.getLotteryTypeName());
		img.setImageResource(lotteryInfo.getLogoRes());
	}

	public int getLotteryId(){
		return  this.lotteryInfo.getLotteryType();
	}


	@Override
	public void countDown() {

	}
}
